#include "GameObject.h"
#include "defines.h"

GameObject::GameObject()
	: m_pAttachGameObject(NULL), m_pParentGameObject(NULL), m_pImage(NULL), m_iColumn(-1), m_iRow(-1)
{	
}
GameObject::~GameObject()
{
	m_pAttachGameObject = 0;
	m_pParentGameObject = 0;
}

bool GameObject::initObject(const char* filePath, CCLayer* parent, float x, float y, int row, int column, BoxupType_e eObjectType)
{
	m_eObjectType = eObjectType;
	m_pImage = GameSprite::gameSpriteWithFile(filePath);
	if (!m_pImage) return false;			
	m_pImage->setPosition(ccp(x, y));
	parent->addChild(m_pImage);	
	m_iColumn = column;
	m_iRow = row;
	return true;
}

bool GameObject::isTouch(CCPoint tap, CCTouch *touch)
{
	if (m_pImage->boundingBox().containsPoint(tap))
	{
		m_pImage->setTouch(touch);		
		return true;
	}

	return false;
}

CCTouch* GameObject::getTouch()
{
	if (m_pImage)
		return m_pImage->getTouch();

	return NULL;
}

void GameObject::setPosition(float x, float y)
{
	if (m_pImage)
		m_pImage->setPosition(ccp(x, y));
}

CCPoint GameObject::getPosition()
{
	if (m_pImage)
		return m_pImage->getPosition();
	return CCPoint(0, 0);
}

void GameObject::setTouch(CCTouch* touch)
{
	if (m_pImage)
		m_pImage->setTouch(touch);
}

void GameObject::release()
{
	if (this->m_pAttachGameObject)
	{
		m_pAttachGameObject->m_pParentGameObject = NULL;
		m_pAttachGameObject->release();
		m_pAttachGameObject = NULL;
	}

	CCObject::release();
}